﻿$(document).ready(function () {
    $("#cmbTipoUsuario").change(function (evt) {
        $.ajax({
            url: "/Menu/consulta_menu",
            dataType: "html",
            cache: false,
            data: {
                id: $("#cmbTipoUsuario").val()
            }
        }).done(function (dat) {
            var js = eval(dat);
            for (var i in js) {
                var id = "ckb_" + js[i].id_menu;
                if (js[i].visible == "S") {
                    document.getElementById(id.toString()).checked = true;
                }
                if (js[i].visible == "N")
                    document.getElementById(id.toString()).checked = false;

                if (js[i].visible == null)
                    document.getElementById(id.toString()).checked = false;
            }
        });
    });
});

function check(id, id_menu) {
    var vi = "";
    if (document.getElementById(id).checked)
        vi = "S";
    else
        vi = "N";
    try {

        $.ajax({
            url: "/Menu/modMenu",
            dataType: "html",
            cache: false,
            data: {
                menu: id_menu,
                tipo: $("#cmbTipoUsuario").val(),
                visible: vi
            }
        }).done(function (dat) {
            //alert(dat);
        });
    } catch (e) {
        alert(e.message);
    }
}
